package com.atguigu.userprofile.dao

import com.atguigu.userprofile.bean.TagInfo
import com.atguigu.userprofile.util.MySqlUtil

object TagInfoDao {

  def getTagInfoByTask(taskId:String): TagInfo ={
    var tagInfo:TagInfo=null
    val selectTagSql=
      s"""
         |  select *  from  tag_info  where tag_task_id =$taskId
          """.stripMargin
    val maybeTagInfo: Option[TagInfo] = MySqlUtil.queryOne(selectTagSql, classOf[TagInfo],true)
    if(maybeTagInfo==None){
      throw new RuntimeException( " no tag  by task_id:"+ taskId)
    }else{
      tagInfo=maybeTagInfo.get
    }
    tagInfo
  }


  def getTagListWithOn(): List[TagInfo] ={
      val selectTagList=
        s"""
           |select tg.id,tag_code,tag_name,parent_tag_id,
           |tag_type,tag_value_type,tag_value_limit,tag_task_id,tag_comment,tg.create_time
           | from tag_info  tg join task_info  tk  on  tg.tag_task_id=tk.id
           |  where  tk.task_status='1'
         """.stripMargin

    val tagInfoList: List[TagInfo] = MySqlUtil.queryList(selectTagList,classOf[TagInfo],true)
    tagInfoList
  }

}
